'''
Created on Sep 5, 2012

@author: peng
'''
import pycurl
import cStringIO
import StringIO
import gzip

sf = cStringIO.StringIO()

post_str = '''w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=launch&t=1346771243604&p=mobi.mgeek.TunnyBrowser&l=en_US&label=mobi.mgeek.TunnyBrowser&m=Nexus%20S&act=launch&h=800
w=480&val=4&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771254644&p=mobi.mgeek.TunnyBrowser&l=en_US&label=usedspeeddialcount&m=Nexus%20S&act=launch&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275613&p=mobi.mgeek.TunnyBrowser&l=en_US&label=ff90821feeb2b02a33a6f9fc8e5f3fcd&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275614&p=mobi.mgeek.TunnyBrowser&l=en_US&label=0&m=Nexus%20S&act=clickedpos&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=theme&t=1346771288677&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=install&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=bookmark%20bar&t=1346771338414&p=mobi.mgeek.TunnyBrowser&l=en_US&label=447c1d819532470f427483b5c2ad32a6&m=Nexus%20S&act=clickurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=addon%20bar&t=1346771352994&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=active&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420634&p=mobi.mgeek.TunnyBrowser&l=en_US&label=87468c07c02e370ef84d4b7e3a668589&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420635&p=mobi.mgeek.TunnyBrowser&l=en_US&label=2&m=Nexus%20S&act=clickedpos&h=800
'''

post_str_2 = '''
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=launch&t=1346771243604&p=mobi.mgeek.TunnyBrowser&l=en_US&label=mobi.mgeek.TunnyBrowser&m=Nexus%20S&act=launch&h=800
w=480&val=4&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771254644&p=mobi.mgeek.TunnyBrowser&l=en_US&label=usedspeeddialcount&m=Nexus%20S&act=launch&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275613&p=mobi.mgeek.TunnyBrowser&l=en_US&label=ff90821feeb2b02a33a6f9fc8e5f3fcd&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275614&p=mobi.mgeek.TunnyBrowser&l=en_US&label=0&m=Nexus%20S&act=clickedpos&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=theme&t=1346771288677&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=install&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=bookmark%20bar&t=1346771338414&p=mobi.mgeek.TunnyBrowser&l=en_US&label=447c1d819532470f427483b5c2ad32a6&m=Nexus%20S&act=clickurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=addon%20bar&t=1346771352994&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=active&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420634&p=mobi.mgeek.TunnyBrowser&l=en_US&label=87468c07c02e370ef84d4b7e3a668589&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420635&p=mobi.mgeek.TunnyBrowser&l=en_US&label=2&m=Nexus%20S&act=clickedpos&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=home&t=1346771911402&p=mobi.mgeek.TunnyBrowser&l=en_US&label=back&m=Nexus%20S&act=hardkey&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771912720&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771914424&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915068&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915838&p=mobi.mgeek.TunnyBrowser&l=en_US&label=4&m=Nexus%20S&act=num&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915867&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771916337&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771916920&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771917799&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771919488&p=mobi.mgeek.TunnyBrowser&l=en_US&label=8&m=Nexus%20S&act=num&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771919515&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771920461&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771921161&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab2&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771921852&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%2
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=launch&t=1346771243604&p=mobi.mgeek.TunnyBrowser&l=en_US&label=mobi.mgeek.TunnyBrowser&m=Nexus%20S&act=launch&h=800
w=480&val=4&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771254644&p=mobi.mgeek.TunnyBrowser&l=en_US&label=usedspeeddialcount&m=Nexus%20S&act=launch&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275613&p=mobi.mgeek.TunnyBrowser&l=en_US&label=ff90821feeb2b02a33a6f9fc8e5f3fcd&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771275614&p=mobi.mgeek.TunnyBrowser&l=en_US&label=0&m=Nexus%20S&act=clickedpos&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=theme&t=1346771288677&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=install&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=bookmark%20bar&t=1346771338414&p=mobi.mgeek.TunnyBrowser&l=en_US&label=447c1d819532470f427483b5c2ad32a6&m=Nexus%20S&act=clickurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=addon%20bar&t=1346771352994&p=mobi.mgeek.TunnyBrowser&l=en_US&label=811711abd41cd659c819d87108f22bce&m=Nexus%20S&act=active&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420634&p=mobi.mgeek.TunnyBrowser&l=en_US&label=87468c07c02e370ef84d4b7e3a668589&m=Nexus%20S&act=clickedurl&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=speed%20dial&t=1346771420635&p=mobi.mgeek.TunnyBrowser&l=en_US&label=2&m=Nexus%20S&act=clickedpos&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=home&t=1346771911402&p=mobi.mgeek.TunnyBrowser&l=en_US&label=back&m=Nexus%20S&act=hardkey&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771912720&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771914424&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915068&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915838&p=mobi.mgeek.TunnyBrowser&l=en_US&label=4&m=Nexus%20S&act=num&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771915867&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771916337&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771916920&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771917799&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771919488&p=mobi.mgeek.TunnyBrowser&l=en_US&label=8&m=Nexus%20S&act=num&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771919515&p=mobi.mgeek.TunnyBrowser&l=en_US&label=newtab&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771920461&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771921161&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab2&m=Nexus%20S&act=click&h=800
w=480&val=1&v=8.8.0%20beta3&u=6e8ffe7b3fb6b5e11da0af5555a6c877&cat=tab%20bar&t=1346771921852&p=mobi.mgeek.TunnyBrowser&l=en_US&label=closetab1&m=Nexus%2
'''
import gzip
# f = gzip.open('/home/peng/1.gz', 'wb')
# f.write(post_str)
# f.close()
#
# f = gzip.open('/home/peng/2.gz', 'wb')
# f.write(post_str_2)
# f.close()

f = gzip.open('/home/peng/1.gz', 'rb')
file_content_1 = f.read()
f.close()

f = gzip.open('/home/peng/2.gz', 'rb')
file_content_2 = f.read()
f.close()

f = open('/home/peng/1.gz', 'rb')
send_1 = f.read()
f.close()

f = open('/home/peng/2.gz', 'rb')
send_2 = f.read()
f.close()

html = StringIO.StringIO()
url = r'https://tracken.dolphin-browser.com/track/pvs.gif'

size = StringIO.StringIO()

c = pycurl.Curl()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HTTPHEADER, ['Content-Encoding:gzip'])
c.setopt(pycurl.POSTFIELDS, send_2)
c.setopt(pycurl.SSL_VERIFYHOST, False)
c.setopt(pycurl.SSL_VERIFYPEER, False)
c.setopt(pycurl.WRITEFUNCTION, html.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.perform()
print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL)
print html.getvalue()
print 'response size [%s]' % html.len
print 'request size [%s]' % c.getinfo(pycurl.CONTENT_LENGTH_UPLOAD)
